﻿package plugin.social.handler
{
    import com.core.*;
    import com.sh.game.global.*;
    import flash.geom.*;
    import manager.*;
    import plugin.social.consts.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;
    import view.message.*;

    public class SocialHandler extends Object implements IGroupHandler
    {
        private var cfgmaps:Array;

        public function SocialHandler()
        {
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            var heilist:Array;
            var key:String;
            var changelist:Object;
            var isTuiJianOpen:Boolean;
            var obj:Object;
            var str:String;
            var datamsg:Object;
            var msgParam:Object;
            var onlineArr:Array;
            var i:int;
            var message:* = param1;
            switch(message.getCmd())
            {
                case CMDSocial.GET_SOCIALLIST:
                {
                    ModelProxy.change("social", "sociallist", message.getParam());
                    break;
                }
                case CMDSocial.APPLYFOR:
                {
                    obj = message.getParam();
                    str = "<font color =\'#00FF00\'>[<U><A href=\"event:user," + obj.rid + "," + obj.name + "\">" + obj.name + "</A></U>]</font><font color =\'#FF0000\'>添加你为好友</font>";
                    ModelProxy.change("chat", "normalmsg", {cmd:8, msg:str});
                    isTuiJianOpen = ModelProxy.getValue("data", "isTuiJianOpen");
                    if (isTuiJianOpen)
                    {
                    }
                    else
                    {
                        ModelProxy.change("mainui", "addFriendChator", [message.getParam()]);
                    }
                    break;
                }
                case CMDSocial.ERROR:
                {
                    ModelProxy.change("movetips", "error", message.getParam());
                    break;
                }
                case CMDSocial.ChangeList:
                {
                    ModelProxy.change("social", "changelist", message.getParam());
                    break;
                }
                case CMDSocial.NewBattler:
                {
                    break;
                }
                case CMDSocial.ChangeData:
                {
                    ModelProxy.change("social", "changedata", message.getParam());
                    break;
                }
                case CMDSocial.GetNewData:
                {
                    this.showSocialtips(message.getParam());
                    ModelProxy.change("social", "getnewdata", message.getParam());
                    break;
                }
                case CMDSocial.JianList:
                {
                    break;
                }
                case CMDSocial.HeiList:
                {
                    heilist = ModelProxy.getValue("data", "heilist");
                    if (heilist == null)
                    {
                        heilist = new Array();
                    }
                    var _loc_3:int = 0;
                    var _loc_4:* = message.getParam();
                    while (_loc_4 in _loc_3)
                    {
                        
                        key = _loc_4[_loc_3];
                        heilist.push(key);
                    }
                    ModelProxy.change("data", "heilist", heilist);
                    break;
                }
                case CMDSocial.AddHei:
                {
                    heilist = ModelProxy.getValue("data", "heilist");
                    changelist = message.getParam();
                    var _loc_3:int = 0;
                    var _loc_4:* = changelist;
                    while (_loc_4 in _loc_3)
                    {
                        
                        key = _loc_4[_loc_3];
                        heilist.push(key);
                    }
                    ModelProxy.change("social", "changelist", message.getParam());
                    break;
                }
                case CMDSocial.delHei:
                {
                    heilist = ModelProxy.getValue("data", "heilist");
                    changelist = message.getParam();
                    var _loc_3:int = 0;
                    var _loc_4:* = changelist;
                    while (_loc_4 in _loc_3)
                    {
                        
                        key = _loc_4[_loc_3];
                        i;
                        while (i < heilist.length)
                        {
                            
                            if (heilist[i] == key)
                            {
                                heilist.splice(i, 1);
                            }
                            i = (i + 1);
                        }
                    }
                    ModelProxy.change("social", "changelist", message.getParam());
                    break;
                }
                case CMDSocial.tracing:
                {
                    ModelProxy.change("social", "tracing", message.getParam());
                    break;
                }
                case CMDSocial.searchRole:
                {
                    ModelProxy.change("social", "searchRole", message.getParam());
                    break;
                }
                case CMDSocial.callFriend:
                {
                    datamsg = message.getParam();
                    Alert2.show("您的好友" + datamsg[1] + "召唤您去帮忙，是否前去？", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                var _loc_3:Output = null;
                if (param1 == 0)
                {
                    _loc_3 = new Output();
                    _loc_3.writeVarInt(datamsg[0], false);
                    PluginManager.instance.sendToBufferServer("social", CMDSocial.Trans, _loc_3);
                }
                else
                {
                    PluginManager.instance.sendToServer("social", CMDSocial.RefuseZhaoHuan, datamsg[0]);
                }
                return;
            }// end function
            );
                    break;
                }
                case CMDSocial.getSomeFriend:
                {
                    isTuiJianOpen = ModelProxy.getValue("data", "isTuiJianOpen");
                    if (isTuiJianOpen)
                    {
                    }
                    else
                    {
                        ModelProxy.change("mainui", "addFriendChator", message.getParam().source);
                    }
                    break;
                }
                case CMDSocial.UpAndDown:
                {
                    msgParam = message.getParam();
                    onlineArr;
                    if (msgParam is String)
                    {
                        return;
                    }
                    switch(msgParam[3])
                    {
                        case -1:
                        {
                            ModelProxy.change("movetips", "error", "您的对手" + msgParam[1] + onlineArr[msgParam[2]]);
                            break;
                        }
                        case 1:
                        {
                            ModelProxy.change("movetips", "error", "您的好友" + msgParam[1] + onlineArr[msgParam[2]]);
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    ModelProxy.change("social", "upAndDown", msgParam);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

        private function showSocialtips(param1) : void
        {
            var _loc_2:String = null;
            if (this.cfgmaps == null)
            {
                this.cfgmaps = ConfigDictionary.data.maplist;
            }
            var _loc_3:* = param1;
            if (_loc_3.online)
            {
                if (this.cfgmaps[_loc_3.stageid] == null)
                {
                    _loc_2 = "情谊值" + _loc_3.qinmi + "\n" + _loc_3.xinqin;
                    ModelProxy.change("tips", "normal", {data:_loc_2, p:new Point(GlobalLayer.instance.root.mouseX, GlobalLayer.instance.root.mouseY)});
                }
                else
                {
                    _loc_2 = this.cfgmaps[_loc_3.stageid].name + " " + _loc_3.x + "," + _loc_3.y + "  情谊值" + _loc_3.qinmi + "\n" + _loc_3.xinqin;
                    ModelProxy.change("tips", "normal", {data:_loc_2, p:new Point(GlobalLayer.instance.root.mouseX, GlobalLayer.instance.root.mouseY)});
                }
            }
            return;
        }// end function

    }
}
